package com.ymatou.iapi.trading.sellerquery.service;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONObject;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.ymatou.iapi.trading.sellerquery.parameter.resp.GetOrderFlowsResp;
import com.ymt.base.YmatouBaseCall;
import com.ymt.core.tool.FormatUtil;
import com.ymttest.utils.DataUtil;
import com.ymttest.utils.EnvSetup;

/**
 * 获取订单资金流信息Call FreeMaker Template自动生成代码
 */
public class GetOrderFlowsCall extends YmatouBaseCall {
	private static String opurl = "api/Order/GetOrderFlows";

	public GetOrderFlowsCall() {
		super(EnvSetup.getSystemUrl("sellerquery_iapi"), opurl, "GET", "JSON");
	}

	@Override
	public void addDefHeader() {
		client.addHeader("Accept",
				"text/xml,text/javascript,text/html,application/json");
		client.addHeader("Content-Type", "application/json; charset=UTF-8");
	}

	/**
	 * 获取Code
	 * 
	 * @return
	 */
	public String getCode() {
		String Code = null;
		try {
			Code = new JSONObject(getReturnData()).getString("code");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Code;
	}

	/**
	 * 获取BCode
	 * 
	 * @return
	 */
	public int getBCode() {
		int BCode = -1;
		try {
			BCode = new JSONObject(getReturnData()).getInt("bcode");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return BCode;
	}

	/**
	 * 获取Msg
	 * 
	 * @return
	 */
	public String getMsg() {
		String BCode = null;
		try {
			BCode = new JSONObject(getReturnData()).getString("msg");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return BCode;
	}

	/**
	 * 获取Data
	 * 
	 * @return
	 */
	public JSONObject getData() {
		JSONObject Data = null;
		try {
			Data = new JSONObject(getReturnData()).getJSONObject("data");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Data;
	}

	/**
	 * 获取订单资金流信息
	 * 
	 * @return
	 */
	public List<GetOrderFlowsResp> getOrderFlowsResp() {
		List<GetOrderFlowsResp> getOrderFlowsRespList = new ArrayList<GetOrderFlowsResp>();
		try {
			String rd = getData().getString("flows");
			Gson gson = new Gson();
			getOrderFlowsRespList = gson.fromJson(rd,
					new TypeToken<ArrayList<GetOrderFlowsResp>>() {
					}.getType());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return getOrderFlowsRespList;
	}

	/**
	 * 获取Data
	 * 
	 * @return
	 */
	public GetOrderFlowsResp getOrderFlowsResponse() {
		GetOrderFlowsResp Data = null;
		try {
			Data = (GetOrderFlowsResp) FormatUtil.GSONToObject(DataUtil.Json.parseJsonObj(getData().toString()).toString(), GetOrderFlowsResp.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Data;
	}

}